package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.lexicon.AuditStateEnum;
import com.yuexunit.finance.project.entity.CommissionExtractApplicationEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

/**
*@version 创建时间：2016年10月10日 上午11:38:46
*@author NTBK-021-1006
*类说明
*/

@Implements(CommissionExtractApplicationService.class)
public class CommissionExtractApplicationServiceImpl implements CommissionExtractApplicationService {

	@Override
	@Transactional
	public Long createCommissionExtractApplication(CommissionExtractApplicationEntity entity) {
		PersistUtil.insert(entity);
		return entity.getExtractId();
	}

	@Override
	@Transactional
	public void updateCommissionExtractApplication(CommissionExtractApplicationEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public CommissionExtractApplicationEntity inquireCommissionExtractApplication(Long extractId) {
		return PersistUtil.get(CommissionExtractApplicationEntity.class, extractId);
	}

	@Override
	public PageList<CommissionExtractApplicationEntity> inquireCommissionExtractApplicationPageList(Integer auditState, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CommissionExtractApplicationEntity.class);
		if (auditState != null) {
			criteria.add(Restrictions.eq("auditState", AuditStateEnum.valueOf(auditState)));
		}
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<Long> countCommissionExtract() {
		DetachedCriteria criteria = DetachedCriteria.forClass(CommissionExtractApplicationEntity.class);
		criteria.add(Restrictions.eq("auditState", AuditStateEnum.UNAUDIT));
		criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("extractId")));
		return PersistUtil.get(criteria);
	}
}
